package com.bdqn.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置
 *
 * @author lilibo
 * @date 2019/9/20
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 测试环境开启
     */
    @Value("${qniao.swagger.enable}")
    private boolean enable;

    @Bean("genApi")
    public Docket testApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("genApi")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.bdqn.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo())
                .enable(enable);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("青鸟接口文档")
                .description("代码生成接口文档")
                .version("1.0")
                .build();
    }

}